package org.sith.taskrunner.util;

import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;

public final class MD5 {

	private static MessageDigest md5;

	public static String getHashCode(String str) {
		StringBuffer hexString = new StringBuffer();
		try {
			md5 = MessageDigest.getInstance("md5");
			md5.reset();
			md5.update(str.getBytes());
			byte messageDigest[] = md5.digest();
			for (int i = 0; i < messageDigest.length; i++) {
				hexString.append(Integer.toHexString(0xFF & messageDigest[i]));
			}
		} catch (NoSuchAlgorithmException e) {
			throw new IllegalStateException(e);
		}

		return hexString.toString();
	}

}
